package com.huang.mylibrary.db;

import android.content.Context;

import com.huang.mylibrary.dao.DaoMaster;
import com.huang.mylibrary.dao.DaoSession;

public class DBHelper {

    private DaoSession mDaoSession;
    private final String DB_NAME = "rhythm.db";

    private volatile static DBHelper dbHelper;

    private UserInfoHelper userInfoHelper;

    private ImageListInfoHelper imageListInfoHelper;

    private DBHelper(Context context) {
        mDaoSession = DaoMaster.newDevSession(context, DB_NAME);
    }


    public UserInfoHelper getUserInfoHelper() {
        if (userInfoHelper == null)
            userInfoHelper = new UserInfoHelper(mDaoSession.getUserInfoDao());
        return userInfoHelper;
    }


    public ImageListInfoHelper getImageListInfoHelper() {
        if (imageListInfoHelper == null) {
            imageListInfoHelper = new ImageListInfoHelper(mDaoSession.getImageListInfoDao());
        }
        return imageListInfoHelper;
    }

    public static void init(Context context) {
        if (dbHelper == null)
            synchronized (DBHelper.class) {
                if (dbHelper == null) {
                    dbHelper = new DBHelper(context);
                }
            }
    }


    public static DBHelper getInstance() {
        return dbHelper;
    }


}
